package com.auto_code.gen_project.service.impl;

import com.auto_code.gen_project.comm.ServiceCode;
import com.auto_code.gen_project.service.ProProjectService;
import com.auto_code.gen_project.util.SpringContextUtil;
import com.auto_code.gen_project.util.project.MicroProjectGenerate;
import com.auto_code.gen_project.util.project.ProjectGenerate;
import com.auto_code.gen_project.util.project.SimpleProjectGenerate;
import com.auto_code.gen_project.vo.BaseRes;
import com.auto_code.gen_project.vo.ProProjectVo;
import org.springframework.stereotype.Service;

@Service
public class ProProjectServiceImpl implements ProProjectService {

    @Override
    public BaseRes<String> genProject(ProProjectVo projectVo) {
        ProjectGenerate proGen = null;

        if("micro".equalsIgnoreCase(projectVo.getProType())) {
            proGen = SpringContextUtil.getBean(MicroProjectGenerate.class);
        } else if("simple".equalsIgnoreCase(projectVo.getProType())) {
            proGen = SpringContextUtil.getBean(SimpleProjectGenerate.class);
        }

        if(null != proGen) {
            try {
                return proGen.genProject(projectVo);
            } catch (Exception e) {
                e.printStackTrace();
                BaseRes<String> res = new BaseRes<>();
                res.setServiceCode(ServiceCode.FAILED);
                res.setMsg(e.getMessage());
            }
        }

        return new BaseRes<>(ServiceCode.SUCCESS);
    }
}
